package com.yungu.swift.system.sys.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.system.sys.dao.SysBusinessOperateLogMapper;
import com.yungu.swift.system.sys.model.dto.SysBusinessOperateLogDto;
import com.yungu.swift.system.sys.model.enums.SysBusinessOperateEnum;
import com.yungu.swift.system.sys.model.param.AdminBusinessOperateLogParam;
import com.yungu.swift.system.sys.model.vo.SysBusinessOperateLogVo;
import com.yungu.swift.system.sys.model.vo.SysOperationCodeVo;
import com.yungu.swift.system.sys.service.SysBusinessOperateLogService;
import com.yungu.swift.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description: 订单操作记录表-SERVICE-IMPL
 * @author:
 * @date: 2019-09-12 16:16
 */
@Service
public class SysBusinessOperateLogServiceImpl extends BaseServiceImpl<SysBusinessOperateLogDto> implements SysBusinessOperateLogService {

    @Autowired
    private SysBusinessOperateLogMapper sysBusinessOperateLogMapper;

    @Override
    protected IMapper<SysBusinessOperateLogDto> getMapper() {
        return sysBusinessOperateLogMapper;
    }

    @Override
    public ResponseData<PageVo<SysBusinessOperateLogVo>> queryPage(AdminBusinessOperateLogParam param) {
        PageBounds pageBounds = new PageBounds(param.getPageNum(), param.getPageSize());
        Map<String, Object> paraMap = MapUtils.convertObjToMap(param);
        PageList<SysBusinessOperateLogVo> rssultList = sysBusinessOperateLogMapper.queryPageList(paraMap, pageBounds);
        PageVo<SysBusinessOperateLogVo> pageVo = new PageVo(param.getPageNum(), param.getPageSize(),
                rssultList.getPaginator().getTotalCount());
        pageVo.setItems(rssultList);
        return ResponseData.buildSuccessResponse(pageVo);
    }

    @Override
    public ResponseData<List<SysOperationCodeVo>> getOperationCode() {
        List<SysOperationCodeVo> codeList = new ArrayList<>();
        for (SysBusinessOperateEnum operateEnum : SysBusinessOperateEnum.values()) {
            SysOperationCodeVo sysOperationCodeVo = new SysOperationCodeVo();
            sysOperationCodeVo.setOperationCode(operateEnum.getCode());
            sysOperationCodeVo.setOperationName(operateEnum.getName());
            codeList.add(sysOperationCodeVo);
        }
        return ResponseData.buildSuccessResponse(codeList);
    }

    @Override
    public ResponseData<Boolean> addBatch(List<SysBusinessOperateLogDto> list) {
        int row = sysBusinessOperateLogMapper.addBatch(list);
        if (row == 0) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "新增日志失败");
        }
        return ResponseData.buildSuccessResponse("新增成功", true);
    }
}